package cn.bdqn.controller;

import cn.bdqn.pojo.Order;
import cn.bdqn.pojo.PageInfo;
import cn.bdqn.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 正文
 * @date 2020/7/20 - 16:10
 */
//我的订单
@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/Orderlist")
    public String gradelist(HttpServletRequest request, Model model, @RequestParam(name = "pn",defaultValue = "1") Integer pn) {
//        List<Grade> emps = null;
//        if(pn <= 1){
//            emps = gradeService.getEmps(id,0);
//        }else{
//            emps = gradeService.getEmps(id,(pn-1)*3);
//        }
//        PageInfo pageInfo = new PageInfo(pn);
//        pageInfo.setTotal(gradeService.getCount(id));
//        pageInfo.setEmps(emps);
//        model.addAttribute("pageInfo",pageInfo);
//        request.getSession().setAttribute("gradelist",pageInfo);
        Integer id = (Integer) request.getSession().getAttribute("id");
        List<Order> emps = null;
        if(pn <= 1){
            emps = orderService.getEmps(id,0);
        }else{
            emps = orderService.getEmps(id,(pn-1)*3);
        }
        for(Order order1:emps){
            if(order1.getStatus()==1){
                order1.setStatuses("已领取");
            }
            if(order1.getStatus()==0){
                order1.setStatuses("未领取");
            }

        }
        PageInfo pageInfo = new PageInfo(pn);
        pageInfo.setTotal(orderService.getCount(id));
        pageInfo.setOrder(emps);
        model.addAttribute("pageInfo",pageInfo);
        request.getSession().setAttribute("orderlist",pageInfo);
        return "personal/dingDan";
    }
}
